﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;
using FA.FlightAttendant.Host;
using FA.FlightAttendant.Plugin;

namespace FA.FlightAttendant.View.Commands
{
    public class StartStopSimulatorCommand : ICommand
    {
        public event EventHandler CanExecuteChanged
        {
            add { CommandManager.RequerySuggested += value; }
            remove { CommandManager.RequerySuggested -= value; }
        }

        public void Execute(object parameter)
        {
            if (!CanExecute(parameter))
                return;

            Simulator sim = (Simulator)parameter;
            if (!sim.IsRunning)
                SimHost.Instance.StartSimulator(sim);
            else
                SimHost.Instance.StopSimulator(sim);
        }

        public bool CanExecute(object parameter)
        {
            return (parameter != null) && (parameter is Simulator) && SimHost.Instance.ManagesSimulator(parameter as Simulator);
        }
    }
}